<!--
  Copyright (c) chb my copyright message. 2022-2023. All rights reserved.

  -->

<template>
  <div class="artistList">
    <!--  顶部标签  -->
    <van-nav-bar title="歌手分类">
      <template #left>
        <van-icon name="zuojiantou" class-prefix="iconfont" size="28px" @click="$router.back()"></van-icon>
      </template>
    </van-nav-bar>
    <div style="width: 100%;height: 60px;font-size: 14px;padding: 10px;background: #ffffff">
      <div class="top1">
        <span style="margin: 0 10px" :class="{current:flag==='7',origin}" @click="changeArea('7')">华语</span>
        <span style="margin: 0 10px" :class="{current:flag==='96',origin}" @click="changeArea('96')">欧美</span>
        <span style="margin: 0 10px" :class="{current:flag==='8',origin}" @click="changeArea('8')">日本</span>
        <span style="margin: 0 10px" :class="{current:flag==='16',origin}" @click="changeArea('16')">韩国</span>
        <span style="margin: 0 10px" :class="{current:flag==='0',origin}" @click="changeArea('0')">其他</span>
      </div>
      <div style="margin-top: 20px">
        <span style="margin: 0 10px" :class="{current:flag2==='1',origin}" @click="changeType('1')">男</span>
        <span style="margin: 0 10px" :class="{current:flag2==='2',origin}" @click="changeType('2')">女</span>
        <span style="margin: 0 10px" :class="{current:flag2==='3',origin}" @click="changeType('3')">乐队/组合</span>
      </div>
    </div>
    <div style="padding: 5px;font-size: 14px;font-weight: 300;">热门歌手</div>
    <div>
      <van-row v-for="(item,index) in topList" :key="index" style="padding: 6px 0">
        <van-col span="4" @click="$router.push({name:'artistIndex',query:{id:item.id}})">
          <img :src="item.picUrl" alt="" style="width: 60px;height: 60px;border-radius: 50%">
        </van-col>
        <van-col span="13" style="line-height: 60px;margin-left: 10px"
                 @click="$router.push({name:'artistIndex',query:{id:item.id}})">
          {{ item.name }}
        </van-col>
        <van-col span="5" style="text-align: center;line-height: 30px;margin-top: 15px">
          <div style="border-radius: 15px" @click="updateArtistesSub(item.id,item.followed)"
               :style="item.followed===true?{color:'#000',border: '1px solid #000'}:{color: '#ce3b36',border: '1px solid #ce3b36'}">
            <van-icon :name="item.followed===true?'success':'plus'"
                      :color="item.followed===true? '#000':'#ce3b36'"></van-icon>
            {{ item.followed === true ? '已关注' : '关注' }}
          </div>
        </van-col>
      </van-row>
    </div>
    <div style="text-align: center" @click="move">点击加载更多</div>
  </div>
</template>

<script>
import {getArtistList, getTopArtists, updateArtistesSub} from "../../api/artist";

export default {
  name: "artistList",
  data() {
    return {
      type: '-1',
      area: '-1',
      limit: 20,
      topList: [],
      origin: 'origin',
      current: 'current',
      flag: 0,
      flag2: 0
    }
  },
  created() {
    this.getArtistLists()
  },
  methods: {
    init() {
      // 热门歌手
      getTopArtists(this.type, this.area, this.limit).then(res => {
        this.topList = []
        this.topList = res.data.artists
      })
    },
    // 歌手分类列表
    getArtistLists() {
      getArtistList(this.type, this.area, this.limit).then(res => {
        if (res.status === 200) {
          this.topList = []
          this.topList = res.data.artists
        }
      })
    },
    changeArea(area) {
      this.area = area
      this.flag = area
      this.getArtistLists()
    },
    changeType(type) {
      this.type = type
      this.flag2 = type
      this.getArtistLists()
    },
    //  加载更多
    move() {
      this.limit += 20
      this.getArtistLists(this.area)
    },
    updateArtistesSub(id, followed) {
      //1为收藏，其他为取消收藏
      let t = followed === true ? '0' : '1'
      updateArtistesSub(id, t).then(res => {
        if (res.status === 200) {
          this.getArtistLists()
          this.$toast.success('操作成功')
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
.artistList {
  background: #f3f3f3;
}

.current {
  color: #ce3b36 !important;

}

.origin {
  color: black;
}
</style>
